<?php
class AdminAction extends Action
{
    /**
    +----------------------------------------------------------
    *类别添加
    +----------------------------------------------------------
    */

    public function adminadd()
    {
        $adminadd=new Model("admin");
        if(isset($_POST['ad_name'])&&isset($_POST['ad_pwd']))
        {
        $data['ad_name']=$_POST['ad_name'];
        $data['ad_pwd']=md5($_POST['ad_pwd']);
        $adminadd_result=$adminadd->data($data)->add();
        if($adminadd_result)
        {
            $this->assign("jumpUrl","adminadd");
            $this->success("管理员添加成功!");

        }
        else
        {
            $this->assign("jumpUrl","adminadd");
            $this->error("管理员添加失败!");

        }
        }
        else
        {
        $this->display();
        }
    }
     /**
    +----------------------------------------------------------
    *类别列表
    +----------------------------------------------------------
    */
     public function adminlist()
    {

         $adminlist=M("admin");
         $adminlist_result=$adminlist->select();
         $this->assign("adminlistshow",$adminlist_result);
         $this->display("adminlist");
     }
      /**
    +----------------------------------------------------------
    *修改类别
    +----------------------------------------------------------
    */
      public function adminedit()
    {
        $adminedit=M("admin");
        if(isset($_GET['e_id']))
        {
            $e_id=$_GET['e_id'];
            $edit_result=$adminedit->where("ad_id=$e_id")->find();
            $this->assign('e_id',$e_id);
            $this->assign('edit_result',$edit_result);
            $this->display(adminedit);
        }
        //更新类别信息
        if(isset($_POST['u_e_id']))
        {
            $u_e_id=$_POST['u_e_id'];
           if(isset($_POST['ad_name'])&&isset($_POST['ad_pwd']))
           {
            $data['ad_name']=$_POST['ad_name'];
            $data['ad_pwd']=md5($_POST['ad_pwd']);
            $info=$adminedit->where("ad_id=$u_e_id")->data($data)->save();
            if($info)
            {
                $this->assign("jumpUrl","adminlist");
                $this->success("管理员修改成功!");
            }
           }

        }
     }
      /**
    +----------------------------------------------------------
    *删除类别
    +----------------------------------------------------------
    */
      public function admindel()
    {
        $admindel=M("admin");
        if(isset($_GET['d_id']))
        {
            $d_id=$_GET['d_id'];
            $del_result=$admindel->where("ad_id=$d_id")->delete();
            if($del_result)
            {
                $this->assign("jumpUrl","__URL__/adminlist");
                $this->success("管理员删除成功!");
            }
        }

     }
}
?>
